<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 *//*
$bar_receipt = sprintf("Time: %s    Receipt No.: %s%cWaiter: %s%c%cItems:%c", date("d/m/Y H:i:s"), "A026342", 10, "BELLE", 10, 10, 10);
$bar_receipt .= chr(27) . "!" . chr(17); //turn on double height mode
$bar_receipt .= sprintf("%s  x%d%c", "Item 1", 1, 10);
$bar_receipt .= sprintf("%s  x%d%c", "Item 2", 1, 10);
$bar_receipt .= sprintf("%s  x%d%c", "Item 3", 1, 10);
$bar_receipt .= sprintf("%s  x%d%c", "Item 4", 1, 10);
$bar_receipt .= chr(27) . "!" . chr(0); //turn off double height mode
$bar_receipt .= "----------- END -------------";
$bar_receipt .= chr(29) . "V" . chr(66) . chr(0); //feed paper and cut
if ($bar_printer1 = printer_open("RPRINTER")) {
//        printer_set_option($bar_printer1, PRINTER_MODE, "text");
    printer_write($bar_printer1, $bar_receipt);
    printer_close($bar_printer1);
}
*/

    $tableno = "OP1";
    $sales = "A00001";
    $waiter = "BELLE";
    $item["name"] = "Beer ABC Btl";
    $bar_receipt = "";
//    $fp = fsockopen("192.168.10.11", 9100, $errno, $errstr, 10);
//    $fp = fopen("LPT1:", "w");
    $fp = fsockopen("192.168.10.11", "9100", $errno, $errstr);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
    //print to bar receipt printer
    //print mether 1:
    $bar_receipt .= "\x1b\x40";  //initialize printer
    $bar_receipt .= "\x1bM\x0";  //select font A
    $bar_receipt .= sprintf("Time: %s Table No.: %s\n" .
            "Receipt No.: %s\n" .
            "Waiter: %s\n" .
            "Items:\n\n", date("d/m/Y H:i:s"), $tableno, $sales, $waiter);
    $bar_receipt .= "\x1d!\x11"; //turn on double height mode
    $bar_receipt .= "\x1bG\x1"; //turn on double height mode
    $bar_receipt .= sprintf("%s  x%d\n", "Item 1", 1);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 2", 2);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 3", 3);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 4", 4);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 5", 5);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 6", 6);
    $bar_receipt .= sprintf("%s  x%d\n", "Item 7", 7);
    $bar_receipt .= "\x1bG\x0"; //turn on double height mode
    $bar_receipt .= "\x1d!\x0"; //turn off double height mode

    $bar_receipt .= "\n\n============== END ==============\n";
    $bar_receipt .= "012345678901234567890123456789012345678901234567\n";
    $bar_receipt .= "\x1dV\x42\x0"; //feed paper and cut
    fprintf($fp, $bar_receipt);
      fclose($fp);
    }
